<script type="text/javascript">
$(function(){
	var pg = App.message.brokerDetails.ui, pp = pg.params,
		catalogLb = pg.children('.navi').seek('title'),
		title = pg.children('.navi').seek('back'),
		keyword = pg.seek('keyword'),
		startDate = pg.seek('startDate'),
		endDate = pg.seek('endDate'),
		startH = pg.seek('startH'),
		startM = pg.seek('startM'),
		startS = pg.seek('startS'),
		endH = pg.seek('endH'),
		endM = pg.seek('endM'),
		endS = pg.seek('endS'),
		qstatus = pg.seek('qstatus');
	
	title.text(pp.broke);
	catalogLb.text(pp.queue.code+'队列积压消息');
		
	var gd = pg.find('.grid').mac('grid', {
		key: 'id',
		cols: [{
			field: 'cId', title : '消息id', width: 260, 
			render: function(r){				
				return r.message.id;
			}
		}, {
			field: 'addTime', title : '添加时间', width: 180,
			render: function(r){
				return new Date(r.addTime).format('yyyy-MM-dd HH:mm:ss.S');
			}
		}, {
			field: 'lastTime', title : '持续时间 ', width: 180,
			render: function(r){
				return new Date(r.lastTime).format('yyyy-MM-dd HH:mm:ss.S');
			}
		}, {
			field: 'status', title : '状态 ', width: 45,
			render: function(r, tr, me){
				return Cache.message.message.status[r.message.status];
			}
		},{
			field: 'tried', title : '尝试次数', width: 60,
		},{
			field: 'memo', title : '备注', width: 260,
		}],
		loader: {
			url: App.ctx + '/broker/message.do',
			params: {
				pageNo: 1, pageSize: 50,target:pp.queue.code,addr:pp.broke
			},
			autoLoad: true
		},
	});
		
	pg.seek('back').click(function(){
		App.show({
			ctx: 'message',
			action: 'brokerQueue',
			params: pp.broke
		}, $.noop, pg.parent());
	});
	
	var dateCfg = {
			prevText: "<上一月",
			nextText: "下一月>",
			dateFormat: "yy-mm-dd",
			changeMonth: true,
			changeYear: true,
			inline: true
	};
	pg.seek('startDate').datepicker(dateCfg); 
	pg.seek('endDate').datepicker(dateCfg); 

	
	function adjust(){
		var h = pg.parent().height();
		pg.height(h);
		gd.parent().height(h - 136);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
	
	function getStartTime(){
		if(startDate.val() == ""){
			return null;
		}
		if(startH.val()<10 || startH.val() == 0){
			var hour = '0' + startH.val();
		}else{
			var hour = startH.val();
		}
		if(startM.val()<10 || startM.val() == 0){
			var minute = '0' + startM.val();
		}else{
			var minute = startM.val();
		}
		if(startS.val()<10 || startS.val() == 0){
			var second = '0' + startS.val();
		}else{
			var second = startS.val();
		}
		return startDate.val()+" " + hour +":" + minute + ":" + second;
	}
	
	function getEndtTime(){
		if(endDate.val() == ""){
			return null;
		}
		if(endH.val()<10 || endH.val() == 0){
			var hour = '0' + endH.val();
		}else{
			var hour = endH.val();
		}
		if(endM.val()<10 || endM.val() == 0){
			var minute = '0' + endM.val();
		}else{
			var minute = endM.val();
		}
		if(endS.val()<10 || endS.val() == 0){
			var second = '0' + endS.val();
		}else{
			var second = endS.val();
		}
		return endDate.val()+" " + hour +":" + minute + ":" + second;
	}
	function validateTime(){
		var start = startDate.val(); 
		var end = endDate.val();
		if(start == '' && end == ''){
			return true;
		}
 		if(start>end){
 			return false;
 		}
 		return true;

	}
 	pg.seek('srchBtn').click(function(e) {
 		console.log(qstatus.val() == undefined?null:qstatus.val());
 		if(!validateTime()){
 			mac.alert('结束时间应大于开始时间');
 		}else{
 	 		gd.load({target:pp.queue.code,key : keyword.val(),status:qstatus.val() == undefined?null:qstatus.val(),
 	 				startTime:getStartTime(),endTime:getEndtTime()}); 
 		}
	});
 	

 	qstatus.mac('combo', {
		keyField: 'k',
		displayField: 'v',
		multiSelect: false,
		width: 120,
		boxWidth: 120,
		cols : [{
			field: 'v', width: 324
		}],
		data: [{ k: 0, v: '新消息' },{ k: 1, v: '已入队' }, { k: 2, v: '已发送' },{ k: 3, v: '已消费' },{ k: 5, v: '已失败' }]
	});
});

</script>
<div class="navi">
	<div class="title">
		当前中间件:<span class="a" name="back">XXX</span>&gt;&gt;
		<span name="title">XX队列积压消息</span>
	</div>
</div>
<div class="filter">
	<div class="keyword-status">
		<div class="title">关键字:</div>
		<input type="text" name="keyword" class="mr10 keyword" />
		<div class="combo fr" name="qstatus" ></div>
		<div class="title fr">消息状态:</div>
	</div>
	<div class="time">
		<div class="title">时间范围:</div>
		<input class="date mr10" name="startDate" />
		<input class="hms "  type="number" max="59" min="0" placeholder="时" name = "startH"/><span class="mr10"></span>
		<input class="hms"  type="number" max="59" min="0" placeholder="分" name = "startM"/><span  class="mr10"></span>
		<input class="hms "  type="number" max="59" min="0" placeholder="秒" name = "startS"/>
		<span>到</span>
		<input class="date mr10" name="endDate" />
		<input class="hms"  type="number" max="59" min="0" placeholder="时" name = "endH"/><span class="mr10"></span>
		<input class="hms"  type="number" max="59" min="0" placeholder="分" name = "endM"/><span class="mr10"></span>
		<input class="hms"  type="number" max="59" min="0" placeholder="秒" name = "endS"/>
	</div>
</div>
<button name="srchBtn">查找</button>
<div class="body">
	<div class="grid"></div>
</div>